package com.ganbo.thread;

import java.util.concurrent.*;

public class CreateThread4 {

    public static void main(String[] args) throws ExecutionException, InterruptedException {

        //创建线程池
        ExecutorService executorService = Executors.newFixedThreadPool(10);

        //提交无返回值的线程任务
        executorService.submit(new Runnable() {
            public void run() {
                System.out.println(Thread.currentThread().getName());
            }
        });

        //提交有返回值的线程任务
        Future<String> submit = executorService.submit(new Callable<String>() {
            public String call() {
                System.out.println(Thread.currentThread().getName());
                return "SUCCESS";
            }
        });

        System.out.println(submit.get()); //获取返回值
        System.out.println(Thread.currentThread().getName());
        executorService.shutdown(); //关闭线程池
    }
}
